<?php
/*

Copyright 2009 Matthew C. Dettinger

This program is free software: you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

function dao_file_add_new_file($config) {
	//print_r($_FILES);
	
	$link = c_establish_db_conn($config);
	
	$fileName = $_FILES[uploadedfile][name];
	$tmpName  = $_FILES[uploadedfile][tmp_name];
	$fileSize = $_FILES[uploadedfile][size];
	$fileType = $_FILES[uploadedfile][type];
	
	// read the file into the program
	$fp = fopen($tmpName, 'r');
	$content = fread($fp, filesize($tmpName));
	//$content = mysqli_real_escape_string($link, $content);
	$content = addslashes($content);
	fclose($fp);
	
	if(!get_magic_quotes_gpc()) {
	    $fileName = addslashes($fileName);
	}
	
	$uuid = c_generate_uuid();
	$query = "INSERT INTO file VALUES ('$uuid', '$_SESSION[user_uuid]', '$fileName', '$content')";
	$result = mysqli_query($link, $query);
	
	if (!$result) {
	    $message  = 'Invalid query: ' . mysqli_error($link) . "\n";
	    $message .= 'Whole query: ' . $query;
	    die($message);
	}
	
	return $uuid;
}

function dao_file_remove_file($file_uuid) {
	
}

function dao_file_list_company_files($company_uuid) {
	
	return $company_files; // array
}

?>